$(function () {
    $("#jqGrid").jqGrid({
        url: '../xatlog/list',
        datatype: "json",
        colModel: [			
//			{ label: '序号', name: 'id', width: 50, key: true },
			{ label: '渠道来源', name: 'qdly', width: 80 }, 			
			{ label: '操作类型', name: 'czlx', width: 80 }, 			
			{ label: '操作主题', name: 'czzt', width: 80 }, 			
			//{ label: '操作链接', name: 'linkurl', width: 80 }, 			
			//{ label: '备注', name: 'mark', width: 80 }, 			
			//{ label: '拓展记录1', name: 'exp1', width: 80 }, 			
			//{ label: '拓展记录2', name: 'exp2', width: 80 }, 			
			//{ label: '拓展记录3', name: 'exp3', width: 80 }, 			
			//{ label: '拓展记录4', name: 'exp4', width: 80 }, 			
			//{ label: '拓展记录5', name: 'exp5', width: 80 }, 			
			{ label: '操作时间', name: 'createtime', width: 80 }			
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 80, 
        autowidth:true,
//        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});


var vm = new Vue({
	el:'#rrapp',
	data:{
		q:{
			qdly: null,
			czzt: null,
			createTimeSatrt: null,
			createTimeEnd: null
		},
		xatLogCzzt:{},
		xatLogQdly:{},
		showList: true,
		title: null,
		xatLog: {}
	},
	//创建后加载
	created: function() {
		xatLogCzzt = {};
		xatLogQdly = {};
		//获取下拉框
		this.getRoleList();
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.xatLog = {};
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
			var url = vm.xatLog.id == null ? "../xatlog/save" : "../xatlog/update";
			$.ajax({
				type: "POST",
			    url: url,
			    data: JSON.stringify(vm.xatLog),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "GET",
				    url: "../xatlog/delete",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get("../xatlog/info/"+id, function(r){
                vm.xatLog = r.xatLog;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
				postData:{
					'czzt': vm.q.czzt,
					'qdly': vm.q.qdly,
					'createTimeSatrt':vm.q.createTimeSatrt,
					'createTimeEnd':vm.q.createTimeEnd},
                page:page
            }).trigger("reloadGrid");
		},
		download: function (event) 	{
				$.ajax({
					type: "GET",
				    url: "../xatlog/list/download.json?czzt="+vm.q.czzt+"&createTimeSatrt="+vm.q.createTimeSatrt+"&createTimeEnd="+vm.q.createTimeEnd,
				    success: function(r){
						if(r.code == 0){
							window.location.href ="../xatlog/list/download/xls.json?fileName="+r.msg;
						}else{
							alert(r.msg);
						}
					}
				});
		},
		getRoleList: function(event){
				$.ajax({
					type: "GET",
				    url: "../xatlog/select.json?qdly="+1,
				    success: function(r){
						if(r.code == 0){
							vm.xatLogCzzt = r.czztList;
							vm.xatLogQdly=r.qdlyList;
						}else{
							alert(r.msg);
						}
					}
				});
		},
		getCzztList: function(event){
				$.ajax({
					type: "GET",
				    url: "../xatlog/select.json?qdly="+vm.q.qdly,
				    success: function(r){
						if(r.code == 0){
							vm.xatLogCzzt = r.czztList;
						}else{
							alert(r.msg);
						}
					}
				});
		}
	}
});
